package com.yanze.service.impl;

import com.yanze.mapper.FriendimageMapper;
import com.yanze.pojo.Friendimage;
import com.yanze.service.FriendImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class FriendImageServiceimpl implements FriendImageService {

    @Autowired
    FriendimageMapper friendimageMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int insertImage(Friendimage imageBean) {
        int flag = friendimageMapper.insert(imageBean);
        return flag;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int insertImages(List<Friendimage> images) {
        int flag = friendimageMapper.insertList(images);
        return flag;
    }


    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<Friendimage> queryImageByFid(Long fid) {
        Example example = new Example(Friendimage.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andLike("friendid", "%" + fid + "%");
        example.orderBy("time").desc();
        List<Friendimage> friendimages = friendimageMapper.selectByExample(example);
        return friendimages;
    }
}
